home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / codecs / mccomponent / mycomponent.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  6.3 KB  |  234 lines

  1. /*
  2.     File:        MyComponent.c
  3.  
  4.     Contains:    simple component sample.
  5.  
  6.     Written by: John Wang    
  7.  
  8.     Copyright:    Copyright © 1994-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/18/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 03/14/94    JW        Re-Created for Universal Headers.
  21.  
  22. */
  23.  
  24. #ifdef THINK_C
  25. #define        applec
  26. #endif
  27.  
  28. #include    <Memory.h>
  29. #include    <Errors.h>
  30. #include    <Components.h>
  31. #include    <Movies.h>
  32. #include    <QuickTimeComponents.h>
  33. #include    <Components.h>
  34. #include    <LowMem.h>
  35.  
  36. #include    "MyComponent.h"
  37. #include    "MyComponentRoutines.h"
  38.  
  39. /* ------------------------------------------------------------------------- */
  40.  
  41. //    Component entry point.
  42. #ifdef powerc
  43. ProcInfoType __procinfo=kPascalStackBased
  44.          | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
  45.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ComponentParameters*)))
  46.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char**)));
  47. #endif
  48. pascal ComponentResult main(ComponentParameters *params, char **storage)
  49. {
  50.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  51.     long                ret;
  52.     
  53.     if ( kDEBUGME )
  54.         DebugStr("\pIn main()");
  55.     
  56.     if ( params->what < 0 ) { 
  57.         switch ( params->what ) {
  58.             case kComponentOpenSelect:
  59.                 return ( CallComponentFunction(params, (ComponentFunctionUPP) MyOpen) );
  60.     
  61.             case kComponentCloseSelect:
  62.                 return ( CallComponentFunctionWithStorage(storage, params,
  63.                         (ComponentFunctionUPP) MyClose) );
  64.                 
  65.             case kComponentCanDoSelect:
  66.                 ret = CallComponentFunction(params, (ComponentFunctionUPP) MyCanDo);
  67.                 if ( ret == false ) {
  68.                     DebugStr("\pIn kComponentCanDoSelect");
  69.                     if ( (**myPrivateGlobals).delegate ) {
  70.                         ret = DelegateComponentCall(params, (**myPrivateGlobals).delegate);
  71.                     }
  72.                 }
  73.                 return ( ret );
  74.     
  75.             case kComponentVersionSelect: 
  76.                 return ( CallComponentFunction(params, (ComponentFunctionUPP) MyVersion) );
  77.     
  78.             case kComponentRegisterSelect: 
  79.                 return ( CallComponentFunctionWithStorage(storage, params,
  80.                         (ComponentFunctionUPP) MyRegister) );
  81.  
  82.             case kComponentTargetSelect: 
  83.                 return ( CallComponentFunctionWithStorage(storage, params,
  84.                         (ComponentFunctionUPP) MyTarget) );
  85.  
  86.             default:
  87.                 return ( paramErr );
  88.         }
  89.     } else {
  90.         switch ( params->what ) {
  91.             case kMCIsPlayerEventSelect:    
  92.                 return ( CallComponentFunctionWithStorage(storage, params,
  93.                         (ComponentFunctionUPP) MyIsPlayerEvent) );
  94.                             
  95.             default:
  96.                 if ( (**myPrivateGlobals).delegate ) {
  97.                     //    If base media handler is targeted, then delegate all unimplemented
  98.                     //    calls to the base media handler.
  99.                     long    ret;
  100.                     
  101.                     ret = DelegateComponentCall(params, (**myPrivateGlobals).delegate);
  102.                     return ( ret );
  103.                 } else {
  104.                     //    If base media handler has not been targeted, then return paramErr.
  105.                     return ( paramErr );
  106.                 }
  107.         }
  108.     }
  109. }
  110.  
  111. /* ------------------------------------------------------------------------- */
  112.  
  113. //    Required component calls.
  114.  
  115. pascal ComponentResult MyOpen(ComponentInstance self)
  116. {
  117.     PrivateGlobals             **myPrivateGlobals;
  118.     ComponentInstance        myComp;
  119.     ComponentDescription    searchComp;
  120.     Component                stdPlayer;
  121.     
  122.     if ( kDEBUGME )
  123.         DebugStr("\pIn MyOpen()");
  124.         
  125.     myPrivateGlobals = nil;
  126.     searchComp.componentType = 'play';
  127.     searchComp.componentSubType = 0;
  128.     searchComp.componentManufacturer = 'appl';
  129.     searchComp.componentFlags = 0x40000000;
  130.     searchComp.componentFlagsMask = 0x40000000;
  131.  
  132.     //    Open base media handler component and target it.
  133.     stdPlayer = FindNextComponent(nil, &searchComp);
  134.     if (stdPlayer == nil) {
  135.         DebugStr("\pCould not find standard movie controller.");
  136.     }
  137.     if ((myComp = OpenComponent(stdPlayer)) == nil) {
  138.         return(componentNotCaptured);
  139.     }
  140.     ComponentSetTarget(myComp, self);
  141.     
  142.     //    Create private variables.
  143.     myPrivateGlobals = (PrivateGlobals **) NewHandleClear(sizeof(PrivateGlobals));
  144.     if ( myPrivateGlobals == nil )
  145.         goto bail;
  146.     
  147.     //    Initialize private variables.
  148.     (**myPrivateGlobals).delegate = myComp;
  149.     (**myPrivateGlobals).fadeStatus = false;
  150.     (**myPrivateGlobals).firstTime = false;
  151.  
  152.     //    Since we've gotten here, everyt hings ok and we can set up the connection.
  153.     SetComponentInstanceStorage(self, (Handle) myPrivateGlobals);
  154.     return ( noErr );
  155.  
  156. bail:
  157.     if ( myPrivateGlobals )
  158.         DisposeHandle((Handle) myPrivateGlobals);
  159.     return ( memFullErr );
  160. }
  161.  
  162. pascal ComponentResult MyClose(Handle storage, ComponentInstance self)
  163. {
  164.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  165.  
  166.     if ( kDEBUGME )
  167.         DebugStr("\pIn MyClose()");
  168.  
  169.     //    Make normal again.
  170.     if ((**myPrivateGlobals).fadeStatus == true)
  171.         SwapWindow(myPrivateGlobals);
  172.         
  173.     //    Dispose of private variables.
  174.     if ( myPrivateGlobals ) {
  175.         if ((**myPrivateGlobals).delegate) {
  176.             CloseComponent((**myPrivateGlobals).delegate);
  177.             (**myPrivateGlobals).delegate = nil;
  178.         }
  179.         DisposeHandle((Handle) myPrivateGlobals);
  180.     }
  181.     
  182.     return ( noErr );
  183. }
  184.  
  185. pascal ComponentResult MyCanDo(short selector)
  186. {    
  187.     if ( kDEBUGME )
  188.         DebugStr("\pIn MyCanDo()");
  189.     
  190.     switch ( selector ) {
  191.     
  192.         //    Required component calls.
  193.         case kComponentOpenSelect:
  194.         case kComponentCloseSelect:
  195.         case kComponentCanDoSelect:
  196.         case kComponentVersionSelect: 
  197.         case kComponentRegisterSelect: 
  198.         case kComponentTargetSelect: 
  199.  
  200.         //    MyComponent specific calls.
  201.         case kMCIsPlayerEventSelect:    
  202.             return ( true );
  203.  
  204.         //    Not handled.
  205.         default:
  206.             return ( false );
  207.     }
  208. }
  209.  
  210. pascal ComponentResult MyVersion()
  211. {
  212.     if ( kDEBUGME )
  213.         DebugStr("\pIn MyVersion()");
  214.  
  215.     return ( (kMyComponentSpec<<16) | (kMyComponentVersion) );
  216. }
  217.  
  218. pascal ComponentResult MyRegister()
  219. {
  220.     return ( false );
  221. }
  222.  
  223. pascal ComponentResult MyTarget(Handle storage, ComponentInstance self)
  224. {
  225.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  226.  
  227.     if ( kDEBUGME )
  228.         DebugStr("\pIn MyTarget()");
  229.  
  230.     //    From now on, self will be the component instance that targeted us.
  231.     (**myPrivateGlobals).self = self;
  232.     
  233.     return ( noErr );
  234. }